# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    def sortedArrayToBST(self, nums):
        if nums:
            mid = len(nums) // 2
            r = TreeNode(nums[mid])
            # r.left = self.sortedArrayToBST(nums[0:mid])
            # r.right = self.sortedArrayToBST(nums[mid+1:])
            r.left, r.right = map(self.sortedArrayToBST, [nums[0:mid], nums[mid+1:]])
            return r

if __name__ == '__main__':
    s = Solution()
    L = [-10, -3, 0, 5, 9]
    r = s.sortedArrayToBST(L)
    print(r)